/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.au.uq.datamining.tree;

import weka.classifiers.trees.Id3;
import weka.classifiers.trees.J48;
import weka.classifiers.trees.LADTree;
import weka.core.Instance;
import weka.core.Instances;

/**
 *
 * @author oracle
 */
public class Tree {

    private Instances instances=null;

    public Instances getInstances() {
        return instances;
    }

    public void setInstances(Instances instances) {
        this.instances = instances;
    }

    public void comprobar(){
        double val=-1;
        try {
            J48 id3 = new J48();
            instances.setClassIndex(instances.numAttributes() - 1);
            id3.buildClassifier(instances);
            /*for(int i=0;i<this.instances.numInstances();i++){
                System.out.println(id3.classifyInstance(instances.instance(i)));
            }*/
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public double getId3(Instance instance) {
        double val=-1;
        try {
            Id3 id3 = new Id3();
            instances.setClassIndex(instances.numAttributes() - 1);
            id3.buildClassifier(instances);
            val=id3.classifyInstance(instance);
            //System.out.println(id3.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return val;
    }

    public double getJ48(Instance instance) {
        double val=-1;
        try {
            J48 j48 = new J48();
            instances.setClassIndex(instances.numAttributes() - 1);
            j48.buildClassifier(instances);
            val=j48.classifyInstance(instance);
            System.out.println(j48.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return val;
    }

    public double getLADTree(Instance instance) {
        double val=-1;
        try {
            LADTree w = new LADTree();
            instances.setClassIndex(instances.numAttributes() - 1);
            w.buildClassifier(instances);
            w.classifyInstance(instance);
            //System.out.println(w.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return val;
    }
}
